﻿using AutoMapper;
using MediatR;
using T_Material.API.Application.Commands.PurchaseCommand;
using T_Material.Domain;
using T_Material.Infrastructure.Interface;

namespace T_Material.API.Application.CommandHandlers.PurchaseHandler
{
    public class PurchaseUpdateCommandHandler : IRequestHandler<PurchaseUpdateCommand, int>
    {
        private readonly IPurchaseRepository purchaseRepository;
        private readonly IMapper mapper;
        public PurchaseUpdateCommandHandler(IPurchaseRepository purchaseRepository, IMapper mapper)
        {
            this.purchaseRepository = purchaseRepository;
            this.mapper = mapper;
        }

        public async Task<int> Handle(PurchaseUpdateCommand request, CancellationToken cancellationToken)
        {
            var info = mapper.Map<Purchase>(request);
            info.Applicant = "小王";
            info.AuditState = 0;
            info.UpdateBy = "李四";
            info.UpdateDate = DateTime.Now;
            info.IsDel = false;
            var res = await purchaseRepository.Update(info);
            return res;
            //var info = new Purchase();
            //info.Id = request.Id;
            //info.GoodsName = request.GoodsName;
            //info.TypeName = request.TypeName;
            //info.Specs = request.Specs;
            //info.Quantity = request.Quantity;
            //info.Country = request.Country;
            //info.Province = request.Province;
            //info.UsageDescription = request.UsageDescription;
            //info.Applicant = "小王";
            //info.DeliveryDate = request.DeliveryDate;
            //info.Remarks = request.Remarks;
            //info.MateriaQluality = request.MateriaQluality;
            //info.ApprovedBy = request.ApprovedBy;
            //info.State = 0;
            //info.UpdateBy = "李四";
            //info.UpdateDate = DateTime.Now;
            //info.IsDel = false;
            //var res = await purchaseRepository.Update(info);
            //return res;
        }
    }
}
